﻿<div class="panel panel-default" ms-controller="DXGL">
    <div class="panel-body">
        <div class="form-group">
            <label>短信接收号码</label>
            <textarea class="form-control szhl_require" ms-duplex="modelData.dxnums" id="dxphone"></textarea>
            <a href="javascript:void(0)" ms-click="GetUserPhone()">+从员工中选取号码</a>
            <a href="javascript:void(0)" ms-click="GetKHPhone()" style="margin-left: 20px">+从客户列表中选取号码</a>
        </div>
        <div class="form-group">
            <label>短信内容（不超过300字）</label>
            <textarea class="form-control szhl_require" maxlength="300" ms-duplex="modelData.dxContent"></textarea>
        </div>

        <div class="form-group">
            <div class="row">
                <div class="col-xs-7">
                    <select class="form-control" ms-duplex="modelData.dxContent">
                        <option value="">从模板中选择</option>
                        <option ms-repeat-item="ColumnData" ms-attr-val="item.TagName" ms-attr-selected="item.TagName==modelData.TagName?'selected':''">{{item.TagName}}</option>
                    </select>
                </div>
                <div class="col-xs-2"><button class="btn btn-primary btn-block btn-sm" ms-click="showTag()">添加模板</button></div>
                <div class="col-xs-5 addtag" style="display:none">
                    <div class="input-group">
                        <input type="text" ms-duplex="TagData.TagName" class="form-control">
                        <span class="input-group-btn">
                            <button class="btn btn-success" ms-click="addTag()">确定</button>
                            <button class="btn btn-danger" ms-click="qxTag()">取消</button>
                        </span>
                    </div>

                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="checkbox">
                <label>
                    <input type="checkbox" ms-click="isDSFS(this)">
                    定时发送
                </label>
                <input type="text" value="" ms-if="isLJ" ms-duplex="modelData.SendTime" class="szhl_form_date_time form-control" placeholder="请输入发送时间" />
            </div>
        </div>
    </div>
</div>
<script>
    var tempmodel = avalon.define({
        $id: "DXGL",
        name: "短信管理",
        iswf: false,//是否属于流程表单
        phone: ComFunJS.getQueryString("phone"),
        isLJ: false,
        ColumnData: [],
        TagData: { "Model": "DXGL", "TagName": "" },
        inittemp: function (strId) {
            if (tempmodel.phone) {
                tempmodel.modelData.dxnums = tempmodel.phone;
            }
            $.getJSON('/API/FTAPI.ashx?Action=GETTAGLIST', { P1: "DXGL" }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    tempmodel.ColumnData = resultData.Result;
                }
            })
            if (strId) {
                //编辑加载数据
                $.getJSON('/API/FTAPI.ashx?Action=GETCCQJMODEL', { P1: strId }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        tempmodel.modelData = resultData.Result;
                        if (tempmodel.modelData.SendTime && tempmodel.modelData.SendTime.length > 10) {
                            tempmodel.modelData.SendTime = tempmodel.modelData.SendTime.substring(0, 10);
                        }

                        setTimeout(" ComFunJS.initForm()", 500)
                    }
                })
            } else {
                ComFunJS.initForm();
            }
          
        },//初始化
        modelData: (!pmodel.pageType && localStorage.getItem(pmodel.FormCode)) ? $.parseJSON(localStorage.getItem(pmodel.FormCode)) : { "dxContent": "", "dxnums": "", "SendTime": "" },
        SaveData: function (btdom, piid) {
            if ($("input[type=checkbox]").prop("checked") && tempmodel.modelData.SendTime == "") {
                parent.layer.tips("发送时间不能为空", dom);
                return;
            }
            if (!$("input[type=checkbox]").prop("checked")) {
                tempmodel.modelData.SendTime = "";
            }
            var modelValue = JSON.stringify(tempmodel.modelData.$model);
            $.post('/API/FTAPI.ashx?Action=ADDDXGL', { "P1": modelValue }, function (result) {
                var result = $.parseJSON(result);
                if (result.ErrorMsg == "") {
                    parent.ComFunJS.winsuccess("发送成功");
                } else {

                    parent.ComFunJS.winsuccess("发送失败");
                }
            })
        }, GetUserPhone: function () {
            parent.ComFunJS.winbtnwin("/View/Base/UserSelect.html", "选择用户手机", 900, 540, {}, function (layero, index) {
                var frameid = $("iframe", $(layero)).attr('id');
                var people = parent.window.frames[frameid].getqiandaopeople();
                $("#dxphone").val(people.phone);
                parent.layer.close(index)
            })
        }, GetKHPhone: function () {
            parent.ComFunJS.winbtnwin("/View/APPBaseView/KHGLSelect.html", "选择客户手机", 900, 540, {}, function (layero, index) {
                var frameid = $("iframe", $(layero)).attr('id');
                var phone = parent.window.frames[frameid].model.GetCheckPhone();
                $("#dxphone").val(phone);
                parent.layer.close(index)
            })
        }, isDSFS: function (dom) {
            tempmodel.isLJ = $(dom).prop("checked");
        },
        addTag: function () {
            if (!tempmodel.TagData.TagName) {
                alert("请输入分类");
                return;
            } else if (tempmodel.TagData.TagName.length > 300) {
                alert("分类不能超过300字");
                return;
            }
            var data = tempmodel.TagData.$model;
            var modelValue = JSON.stringify(data);
            $.post("/API/FTAPI.ashx?ACTION=ADDTAG", { P1: modelValue }, function (result) {
                var jsonresult = $.parseJSON(result)
                if ($.trim(jsonresult.ErrorMsg) == "") {
                    tempmodel.ColumnData.push(jsonresult.Result);
                    tempmodel.modelData.TagName = jsonresult.Result.TagName;
                    ComFunJS.winsuccess("操作成功");
                    $(".addtag").hide().prev().show();
                }
            });
        }, qxTag: function () {
            $(".addtag").hide().prev().show();
        }, showTag: function () {
            $(".addtag").show().prev().hide();
        } 
    });
    tempmodel.$watch("modelData.*", function (a, b) {
        if (!tempmodel.modelData.ID) {
            localStorage.setItem(pmodel.FormCode, JSON.stringify(tempmodel.modelData.$model));
        }
    })
</script>